//
//  ProductSwitchCell.m
//  
//
//  Created by Abner on 16/4/28.
//
//

#import "ProductSwitchCell.h"
#import "AddProduct.h"

@interface ProductSwitchCell ()
{
    UIView *_topLine; //cell最上面的线，UI要求的，只有indexPath.row == 0时显示；
}
@end

@implementation ProductSwitchCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _topLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 1)];
        _topLine.backgroundColor = SetColorRGBValue(0xe0e0e0, 1.0);
        _topLine.alpha = 0.5;
        [self.contentView addSubview:_topLine];
        
        self.leftLb = [[UILabel alloc]init];
        [self.contentView addSubview:self.leftLb];
        self.leftLb.font = KAddLeftLbFont;
        self.leftLb.textColor = KAddLeftLbColor;
        self.leftLb.frame = CGRectMake(10, 0, 180, 44);
        
        self.rightSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(ScreenWidth-60, 7, 40, 24)];
        //self.accessoryView = self.rightSwitch;
        [self.contentView addSubview:self.rightSwitch];
        [self.rightSwitch addTarget:self action:@selector(rightSwitchClicked) forControlEvents:UIControlEventTouchUpInside];

        [self.rightSwitch setOnTintColor:SetColorRGBValue(0xFF6800, 1.0)];

        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 44, ScreenWidth, 1)];
        line.backgroundColor = SetColorRGBValue(0xe0e0e0, 1.0);
        line.alpha = 0.5;
        [self.contentView addSubview:line];
        
    }
    return self;
}
#pragma mark --- rightSwitchClicked点击事件
-(void)rightSwitchClicked
{
    if (self.rightSwitchClickedBlock) {
        self.rightSwitchClickedBlock(self.rightSwitch.on);
    }
}
#pragma mark 根据indexpath.row来设置
-(void)setupProductSwitchCell:(CGFloat)aRow aLCProduct:(AddProduct *)aLCProduct
{
    if (aRow == 0) {
        _topLine.hidden = NO;
        self.leftLb.text = @"是否支持快递配送";
        if ([aLCProduct.supportexpress isEqualToString:@"1"]) {
            self.rightSwitch.on = YES;
        }else{
            self.rightSwitch.on = NO;
        }
    }else if (aRow == 1) {
        _topLine.hidden = YES;
        self.leftLb.text = @"是否热卖";
        if ([aLCProduct.ishot isEqualToString:@"1"]) {
            self.rightSwitch.on = YES;
        }else{
            self.rightSwitch.on = NO;
        }
    }else if(aRow == 2){
        _topLine.hidden = YES;
        self.leftLb.text = @"是否上架";
        if ([aLCProduct.ispublic isEqualToString:@"1"]) {
            self.rightSwitch.on = YES;
        }else{
            self.rightSwitch.on = NO;
        }
    }

}
+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *indetifier = @"ProductSwitchCellIdentifier";
    ProductSwitchCell *cell = [tableView dequeueReusableCellWithIdentifier:indetifier];
    if (!cell) {
        cell = [[ProductSwitchCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetifier];
    }
    return cell;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
